package com.publishproject.test;

import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;

import com.publishproject.test.aidl.Book;

import java.util.List;

/**
 * @author Android客户端组-tanghongbin
 * @Title: ArticleManagerIml
 * @Package com.publishproject.test
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @date 2017/1/10 15:59
 * @Description: TODO
 */
public class ArticleManagerIml  {
    public static class Stub extends Binder implements ArticleManager{
        private static final int ADD_BOOK  = 1;
        private static final int GET_BOOKS = 2;

        private IBinder iBinder;

        public Stub(IBinder iBinder) {
            this.iBinder =  iBinder;
        }
        @Override
        public void addBook(Book book) {
            Parcel data = android.os.Parcel.obtain();
            Parcel reply = android.os.Parcel.obtain();
            data.writeParcelable(book,0);
            try {
                iBinder.transact(ADD_BOOK,data,reply,0);
            } catch (RemoteException e) {
                e.printStackTrace();
            }finally {
                data.recycle();
                reply.recycle();
            }
        }

        @Override
        public List<Book> getBooks() {
            return null;
        }

        @Override
        public IBinder asBinder() {
            return this;
        }
    }
}
